package com.zhouyu;

import china.MakerApplication;
import com.zhouyu.service.OrderService;
import org.aopalliance.intercept.Interceptor;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.aspectj.*;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.context.support.ServletContextResource;

import javax.servlet.ServletContext;
import javax.sql.DataSource;
import java.lang.reflect.Method;

@ComponentScan(value = {"com"  })
@EnableScheduling
@PropertySource("classpath:spring.properties")
@EnableAspectJAutoProxy
public class AppConfig {




//	@Bean
//	public ProxyFactoryBean tomProxy(){
//		Tom tom = new Tom();
// 		ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
//		proxyFactoryBean.setTarget(tom);
//  		proxyFactoryBean.addAdvice(new MethodBeforeAdvice() {
//			@Override
//			public void before(Method method, Object[] args, Object target) throws Throwable {
//				System.out.println("=========0000000000000");
//			}
//		});
//		MethodInterceptor methodInterceptor = new MethodInterceptor() {
//			@Nullable
//			@Override
//			public Object invoke(@NotNull MethodInvocation invocation) throws Throwable {
//				System.out.println("111111111" + this.getClass());
//				Object proceed = invocation.proceed();
//				System.out.println("22222222222");
//				return null;
//			}
//		};
//		proxyFactoryBean.addAdvice(methodInterceptor);
// 		return proxyFactoryBean;
//	}

//	@Bean
//	public BeanNameAutoProxyCreator beanNameAutoProxyCreator(){
//		BeanNameAutoProxyCreator beanNameAutoProxyCreator = new BeanNameAutoProxyCreator();
//		beanNameAutoProxyCreator.setBeanNames("tom");
//		beanNameAutoProxyCreator.setInterceptorNames("methodBeforeAdvice");
//		return beanNameAutoProxyCreator;
//	}
//
//	@Bean
//	public MethodBeforeAdvice methodBeforeAdvice(){
//		MethodBeforeAdvice be = new MethodBeforeAdvice() {
//
//			@Override
//			public void before(Method method, Object[] args, Object target) throws Throwable {
//				if (target.getClass().getTypeName().contains("Tom")) {
//					System.out.println("测试-------111111111111");
//				}
//			}
//		};
//		return be;
//	}
//	@Bean
//	public JdbcTemplate jdbcTemplate() {
//		return new JdbcTemplate(dataSource());
//	}
//
//	@Bean
//	public PlatformTransactionManager transactionManager() {
//		DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
//		transactionManager.setDataSource(dataSource());
//		return transactionManager;
//	}
//
//	@Bean
//	public DataSource dataSource() {
//		DriverManagerDataSource dataSource = new DriverManagerDataSource();
//		dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/tuling?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai");
//		dataSource.setUsername("root");
//		dataSource.setPassword("Zhouyu123456***");
//		return dataSource;
//	}


	//
//	@Bean
//	public SqlSessionFactory sqlSessionFactory() throws Exception {
//		SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
//		sessionFactoryBean.setDataSource(dataSource());
//		return sessionFactoryBean.getObject();
//	}
//
//	@Bean
//	public SqlSessionTemplate sqlSession() throws Exception {
//		return new SqlSessionTemplate(sqlSessionFactory());
//	}

}

